package com.kensure.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import co.kensure.frame.ResultInfo;
import co.kensure.frame.ResultRowInfo;
import co.kensure.http.RequestUtils;

import com.alibaba.fastjson.JSONObject;
import com.kensure.mycom.em.model.Employer;
import com.kensure.mycom.em.service.EmployerLoginService;
import com.kensure.mycom.em.service.EmployerService;

/**
 * 员工的逻辑处理
 * 
 * @author fankaidi
 *
 */
@Controller
@RequestMapping(value = "em")
public class EmployerController {

	@Resource
	private EmployerLoginService employerLoginService;
	@Resource
	private EmployerService employerService;

	/**
	 * 用户登录
	 */
	@ResponseBody
	@RequestMapping(value = "login.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo taobao(HttpServletRequest req, HttpServletResponse rep) {
		JSONObject json = RequestUtils.paramToJson(req);
		String loginname = json.getString("loginname");
		String password = json.getString("password");
		String adb = employerLoginService.login(loginname, password);
		return new ResultRowInfo(adb);
	}

	/**
	 * 根据会话获取用户信息
	 */
	@ResponseBody
	@RequestMapping(value = "getuser.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
	public ResultInfo getuser(HttpServletRequest req, HttpServletResponse rep) {
		String token = req.getParameter("emtokenid");
		Employer u = employerService.getUserByToken(token);
		return new ResultRowInfo(u);
	}

}
